#!/usr/bin/env python


# remove rows with nothing in them due to some eccentricity
# in the HTML used to populate them.

import sqlite3

db = sqlite3.connect('recipe_db.sqlite')
db.text_factory = str		# odd workaround for 8 bit strings

print "Deleted", db.execute("""delete from recipes where ingredients like
 					\"['']\" or ingredients like '[]'""").rowcount, "rows"
db.commit()



# sqlite3 supports a neutered version of ALTER TABLE which
# can't remove columns.  here you go.

BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(name, ingredients, category, directions);
INSERT INTO t1_backup SELECT name, ingredients, category, directions FROM recipes;
DROP TABLE recipes;
CREATE TABLE recipes(name, ingredients, category, directions);
INSERT INTO recipes SELECT name, ingredients, category, directions FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;